<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>添加文章</title>
    <link rel="stylesheet" href="/frame/layui/css/layui.css">
    <style>
        .layui-card-body{
            padding-top: 30px;
        }
        .layui-card-body textarea{
            min-height: 400px;
        }
        body{
            padding-bottom: 200px;
        }
        @media screen and (max-width: 480px){
            .layui-form-label {
                width: 30px;
            }
            .layui-input-block{
                margin-left: 70px;
            }
        }
    </style>
</head>
<body>
<fieldset class="layui-elem-field layui-field-title">
    <legend>添加新文章</legend>
</fieldset>
<div class="layui-card">
    <div class="layui-card-body">
        <form class="layui-form" enctype="multipart/form-data" autocomplete="off" method="post" role="form" id="upForm">
            <div class="layui-form-item">
                <label class="layui-form-label">标题</label>
                <div class="layui-input-block">
                    <input type="text" name="title" required  lay-verify="required" placeholder="请输入文章标题" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item layui-form-text">
                <label class="layui-form-label">正文</label>
                <div class="layui-input-block">
                    <textarea placeholder="请输入内容"  required  lay-verify="required" class="layui-textarea" name="content"></textarea>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button type="button" class="layui-btn" lay-submit lay-filter="addart">立即提交</button>
                    <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                </div>
            </div>
        </form>
    </div>
</div>
<script src="frame/layui/layui.js"></script>
<script>
    layui.use(['form','element','jquery'], function(){
        let form = layui.form;
        let element = layui.element;
        let $ = layui.jquery;
        //控制显示宽高
        let iframe= window.parent.document.getElementById('iframe');
        iframe.style.height=document.body.clientHeight +'px';

        form.on('submit(addart)',function (data) {
            $.ajax({
                type:'post',
                dataType:'json',
                url:'/addart/add',
                data:data.field,
                success:function (res) {
                    if(res === '添加成功'){
                        layer.msg(res,{
                            icon:6
                        })
                        setTimeout(function () {
                            top.location.reload();
                        },1000)
                    }else{
                        layer.msg(res,{
                            icon:5
                        })
                    }
                },
                error:function (err) {
                    layer.msg(err,{
                        icon:5
                    })
                }
            })
        })

    });
</script>
</body>
</html>